import wx

class LoginDialog(wx.Dialog):
	def __init__(
			self, parent, ID, title, settingsEncrypted, settingsProtocol, size=wx.DefaultSize, pos=wx.DefaultPosition, 
			style=wx.DEFAULT_DIALOG_STYLE,
			useMetal=False
			):

		# Instead of calling wx.Dialog.__init__ we precreate the dialog
		# so we can set an extra style that must be set before
		# creation, and then we create the GUI object using the Create
		# method.
		pre = wx.PreDialog()
		pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
		pre.Create(parent, ID, title, pos, size, style)

		# This next step is the most important, it turns this Python
		# object into the real wrapper of the dialog (instead of pre)
		# as far as the wxPython extension is concerned.
		self.PostCreate(pre)

		# This extra style can be set after the UI object has been created.
		if 'wxMac' in wx.PlatformInfo and useMetal:
			self.SetExtraStyle(wx.DIALOG_EX_METAL)


		# Now continue with the normal construction of the dialog
		# contents
		sizer = wx.BoxSizer(wx.VERTICAL)

		box = wx.BoxSizer(wx.HORIZONTAL)

		if (settingsEncrypted):
			png = wx.Image('Y:\\encrypted.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
			wBitmap = wx.StaticBitmap(self, -1, png, (0,0), (png.GetWidth(), png.GetHeight()))
			wBitmap.SetHelpText("Connecting over " + settingsProtocol + " (Secure)")
		else:
			png = wx.Image('Y:\\unencrypted.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
			wBitmap = wx.StaticBitmap(self, -1, png, (0,0), (png.GetWidth(), png.GetHeight()))
			wBitmap.SetHelpText("Connecting over " + settingsProtocol + " (Insecure)")

		box.Add(wBitmap, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

		if (settingsEncrypted):
			label = wx.StaticText(self, -1, "Authentication required (Secured Connection over " + settingsProtocol + "):")
		else:
			label = wx.StaticText(self, -1, "Authentication required (Unsecured Connection over " + settingsProtocol + "):")
		label.SetHelpText("Authentication is required for you to access this subversion repository.")
		box.Add(label, 1, wx.ALIGN_CENTRE|wx.ALL, 5)

		sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

		line2 = wx.StaticLine(self, -1, size=(300,-1), style=wx.LI_HORIZONTAL)
		sizer.Add(line2, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)

		box = wx.BoxSizer(wx.HORIZONTAL)

		label = wx.StaticText(self, -1, "Username:", size=(100,-1))
		box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

		text = wx.TextCtrl(self, -1, "", size=(80,-1))
		text.SetHelpText("Enter your subversion username here.")
		box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
		self.UsernameBox = text

		sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

		box = wx.BoxSizer(wx.HORIZONTAL)

		label = wx.StaticText(self, -1, "Password:", size=(100,-1))
		box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

		text = wx.TextCtrl(self, -1, "", size=(80,-1), style=wx.TE_PASSWORD)
		text.SetHelpText("Enter your subversion password here.  Depending on the type of connection, it may be sent in plaintext.")
		box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
		self.PasswordBox = text

		sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

		line = wx.StaticLine(self, -1, size=(300,-1), style=wx.LI_HORIZONTAL)
		sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)

		btnsizer = wx.StdDialogButtonSizer()
		
		if wx.Platform != "__WXMSW__":
			btn = wx.ContextHelpButton(self)
			btnsizer.AddButton(btn)
		
		btn = wx.Button(self, wx.ID_OK)
		btn.SetHelpText("Press OK to continue logging into Subversion.")
		btn.SetDefault()
		btnsizer.AddButton(btn)

		btn = wx.Button(self, wx.ID_CANCEL)
		btn.SetHelpText("Cancel the authentication.")
		btnsizer.AddButton(btn)
		btnsizer.Realize()

		sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

		self.SetSizer(sizer)
		sizer.Fit(self)

class SSLTrustPromptDialog(wx.Dialog):
	def __init__(
			self, parent, ID, title, hostname, realm, size=wx.DefaultSize, pos=wx.DefaultPosition, 
			style=wx.DEFAULT_DIALOG_STYLE,
			useMetal=False,
			):

		# Instead of calling wx.Dialog.__init__ we precreate the dialog
		# so we can set an extra style that must be set before
		# creation, and then we create the GUI object using the Create
		# method.
		pre = wx.PreDialog()
		pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
		pre.Create(parent, ID, title, pos, size, style)

		# This next step is the most important, it turns this Python
		# object into the real wrapper of the dialog (instead of pre)
		# as far as the wxPython extension is concerned.
		self.PostCreate(pre)

		# This extra style can be set after the UI object has been created.
		if 'wxMac' in wx.PlatformInfo and useMetal:
			self.SetExtraStyle(wx.DIALOG_EX_METAL)


		# Now continue with the normal construction of the dialog
		# contents
		sizer = wx.BoxSizer(wx.VERTICAL)

		box = wx.BoxSizer(wx.HORIZONTAL)

		png = wx.Image('Y:\\sslunknown.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
		wBitmap = wx.StaticBitmap(self, -1, png, (0,0), (png.GetWidth(), png.GetHeight()))

		box.Add(wBitmap, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

		label = wx.StaticText(self, -1, "Accept this SSL certificate?")
		label.SetHelpText("SubPython has not seen this server before and it is requesting an SSL connection.")
		box.Add(label, 1, wx.ALIGN_CENTRE|wx.ALL, 5)

		sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

		line2 = wx.StaticLine(self, -1, size=(300,-1), style=wx.LI_HORIZONTAL)
		sizer.Add(line2, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)

		box = wx.BoxSizer(wx.HORIZONTAL)

		label = wx.StaticText(self, -1, "Hostname:", size=(80,-1))
		box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

		label = wx.StaticText(self, -1, hostname, size=(100,-1))
		label.SetHelpText("This is the hostname that the SSL certificate is coming from.")
		box.Add(label, 1, wx.ALIGN_CENTRE|wx.ALL, 5)

		sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

		box = wx.BoxSizer(wx.HORIZONTAL)

		label = wx.StaticText(self, -1, "Realm:", size=(80,-1))
		box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

		label = wx.StaticText(self, -1, realm, size=(250,-1))
		label.SetHelpText("This is the realm.")
		box.Add(label, 1, wx.ALIGN_CENTRE|wx.ALL, 5)

		sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

		line = wx.StaticLine(self, -1, size=(300,-1), style=wx.LI_HORIZONTAL)
		sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)

		btnsizer = wx.StdDialogButtonSizer()
		
		if wx.Platform != "__WXMSW__":
			btn = wx.ContextHelpButton(self)
			btnsizer.AddButton(btn)
		
		btn = wx.Button(self, wx.ID_YES)
		btn.SetHelpText("Accept the certificate.")
		self.Bind(wx.EVT_BUTTON, self.YesPressed, btn)
		btnsizer.AddButton(btn)

		btn = wx.Button(self, wx.ID_NO)
		btn.SetHelpText("Deny the certificate.")
		self.Bind(wx.EVT_BUTTON, self.NoPressed, btn)
		btn.SetDefault()
		btnsizer.AddButton(btn)
		btnsizer.Realize()

		sizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)

		self.SetSizer(sizer)
		sizer.Fit(self)
	
	def YesPressed(self,event):
		self.EndModal(wx.ID_YES)
		pass
	
	def NoPressed(self,event):
		self.EndModal(wx.ID_NO)
		pass
	